Overview

Scala, short for Scalable Language, is a hybrid functional programming language. It was created by Martin Odersky. Scala smoothly integrates the features of object-oriented and functional languages. Scala is compiled to run on the Java Virtual Machine. Many existing companies, who depend on Java for business critical applications, are turning to Scala to boost their development productivity, applications scalability and overall reliability.

Here we have presented a few points that makes Scala the first choice of application developers.

Scala is object-oriented

Scala is a pure object-oriented language in the sense that every value is an object. Types and behavior of objects are described by classes and traits which will be explained in subsequent chapters. Classes are extended by subclassing and a flexible mixin-based composition mechanism as a clean replacement for multiple inheritance.

Scala is functional
Scala is a programming language that has implemented major functional programming concepts. In Functional programming, every computation is treated as a mathematical function which avoids states and mutable data. The functional programming exhibits following characteristics:
  • Power and flexibility
  • Simplicity
  • Suitable for parallel processing
Scala, unlike some of the other statically typed languages (C, Pascal, Rust, etc.), does not expect you to provide redundant type information. You don't have to specify a type in most cases, and you certainly don't have to repeat it.

Scala runs on the JVM

Scala is compiled into Java Byte Code which is executed by the Java Virtual Machine (JVM). This means that Scala and Java have a common runtime platform. You can easily move from Java to Scala. The Scala compiler compiles your Scala code into Java Byte Code, which can then be executed by the 'scala' command. The 'scala' command is similar to the java command, in that it executes your compiled Scala code.

Scala can Execute Java Code
Scala enables you to use all the classes of the Java SDK and also your own custom Java classes, or your favorite Java open source projects.

Scala can do Concurrent & Synchronize processing

Scala allows you to express general programming patterns in an effective way. It reduces the number of lines and helps the programmer to code in a type-safe way. It allows you to write codes in an immutable manner, which makes it easy to apply concurrency and parallelism (Synchronize).

Scala vs Java
Scala has a set of features that completely differ from Java. Some of these are −
  • All types are objects
  • Type inference
  • Nested Functions
  • Functions are objects
  • Domain specific language (DSL) support
  • Traits
  • Closures
  • Concurrency support inspired by Erlang
Difference Between Java and Scala Code
 Java Code    
 Scala Code
public static List<Integer> getEvenNumbersMultpliedBy(List<Integer> numbers) {
List<Integer> results = new ArrayList<>();
for (int number: numbers) {
if (number % 2 == 0) {
int newNumber = number * 10;
results.add(newNumber);
}
}
return results;
}
def evenNumbersMultiplied(numbers: List[Integer]) = numbers.filter(_ %2 == 0).map(_ * 10)

No comments:

Post a Comment